package com.guigu.connler;

import com.guigu.pojo.Vip;
import com.guigu.service.HvipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@RestController


public class UploadVueController {
    @Autowired
    HvipService hvipService;
    @RequestMapping("upload")
    public int updateItemById(@RequestParam("pictureFile") MultipartFile pictureFile, Vip vip) throws Exception {
        System.out.println(vip.getVipid());
        // 图片上传
        // 设置图片名称，不能重复，可以使用uuid
        String picName = UUID.randomUUID().toString();

        // 获取文件名
        String oriName = pictureFile.getOriginalFilename();
        // 获取图片后缀
        String extName = oriName.substring(oriName.lastIndexOf("."));

        File file=new File("h:/upload/image/");
        if (!file.exists()){
            file.mkdirs();

        }
        // 开始上传
        pictureFile.transferTo(new File("h:/upload/image/" + picName + extName));

        String newFIleName=picName+extName;

        Vip vip1 = new Vip();
        vip1.setVid(Integer.parseInt(vip.getVipid()));
        vip1.setVipname(vip.getVipname());
        int updatatp = hvipService.updatatp(vip);
        // 设置图片名到商品中
       // item.setPic(picName + extName);
        // ---------------------------------------------
        // 更新商品
        //this.itemService.updateItemById(item);

        return updatatp;
    }
//    @RequestMapping("upload")
//   int [] selevip(@RequestBody Vip record){
//        Date date1 = new Date();
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd ");
//        String format = formatter.format(date1);
//        String year1 = format.substring(0, 4);
//        String month = format.substring(5, 7);
//        String day1=format.substring(8,10);
//        System.out.println("当前月份"+month);
//        System.out.println("天数"+day1);
//        System.out.println(year1);
//        Vip bean=new Vip();
//        System.out.println("当前年份");
//        bean.setCyear(year1);
//        bean.setCmonth(month);
//        bean.setCday(day1);
//        System.out.println("倒计时"+bean);
////        Pattern pattern = Pattern.compile(rexp);
////        if(year!=""|| year !=null){
//        //判断将人数放在数组对应的地方
//        List<Vip> selecountmebers = hvipService.seleviptme(record);
////人数
//        String [] id = new String[12];
////最终结果
//        int [] date = new int[12];
////日期
//        String [] dates=new String[12];
//        for(int i = 0; i<selecountmebers.size();i++){
//            dates[i]=selecountmebers.get(i).getVipdltime().toString().substring(1,2);
//            id[i]=selecountmebers.get(i).getVid().toString();
//            if(selecountmebers.get(i).getVipdltime().equals("11") ||selecountmebers.get(i).getVipdltime().equals("12")){
//                dates[i]=selecountmebers.get(i).getVipdltime();
//                id[i]=selecountmebers.get(i).getVid().toString();
//            }
//        }
//        for(int i = 0; i<date.length;i++) {
//            String aa = dates[i];
//            if (aa != null) {
//                date[Integer.parseInt(aa) - 1] = Integer.parseInt(id[i]);
//            }
//        }
//        return date;
////            Matcher startM = pattern.matcher(substring);
////            if(startM.matches() == false){
////                System.out.println("格式错误");
////            }else{
////                System.out.println("格式正确");
////
////            }
////        }
//    }
    }

